package com.example.oceanbase.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.sql.DataSource;
import java.sql.*;

@Controller
@RequestMapping(value = "/test")
public class TestController {

    @Autowired
    private DataSource dataSource;

    @GetMapping(value = "/obd")
    public String test() throws SQLException {
        Connection connection = dataSource.getConnection();
        PreparedStatement preparedStatement = connection.prepareStatement("select 1");
        Statement statement = connection.createStatement();
        boolean execute = preparedStatement.execute();
        ResultSet resultSet = statement.executeQuery("select * from __all_auto_increment");
        while (resultSet.next()) {
            // 获取列的数据
            long id = resultSet.getLong("column_id");

            // 打印结果
            System.out.println("ID: " + id);
        }
        return "ok";
    }
}
